<?php

class Application_Model_Dao_DensityMapper
{
	protected $_dbTable;
   
	public function setDbTable($dbTable)
	{
		if (is_string($dbTable)) {
			$dbTable = new $dbTable();
		}
		if (!$dbTable instanceof Zend_Db_Table_Abstract) {
			throw new Exception('Invalid table data gateway provided');
		}
		$this->_dbTable = $dbTable;
		return $this;
	}
   
	public function getDbTable()
	{
		if (null === $this->_dbTable) {
			$this->setDbTable('Application_Model_DbTable_Density');
		}
		return $this->_dbTable;
	}
   

   
	public function find($steelId, $specs)
	{
		$result = $this->getDbTable()->find($steelId, $specs);
		if (0 == count($result)) {
			return;
		}
		$row = $result->current();
		return $this->toModel($row);		
	}
   
	public function fetchAll()
	{
		$resultSet = $this->getDbTable()->fetchAll(null,"steel_id, specs");
		$entries   = array();
		foreach ($resultSet as $row) {	
			$entry = $this->toModel($row);
			$entries[] = $entry;
		}
		return $entries;
	}
	
	private function toModel($record){
		$density = new Application_Model_BusiInfo_Density(); 
		$density->set_steelId($record->steel_id);
	    $density->set_specs($record->specs);
	    $density->set_density($record->density);
	    return $density;
		
	}
	
}

